#include "../stdafx.h"
#include "Tile.h"
namespace Model{


void Tile::setUpNeighbor(Tile* t){
	switch(this->ori){
	case midday: this->neighbor1=t;break;
	case quarter: this->neighbor4=t;break;
	case half: this->neighbor3=t;break;
	case threeQuarter: this->neighbor2=t;break;
	}
}
void Tile::setDownNeighbor(Tile* t){
	switch(this->ori){
	case midday: this->neighbor3=t;break;
	case quarter: this->neighbor2=t;break;
	case half: this->neighbor1=t;break;
	case threeQuarter: this->neighbor4=t;break;
	}
}
void Tile::setLeftNeighbor(Tile* t){
	switch(this->ori){
	case midday: this->neighbor4=t;break;
	case quarter: this->neighbor3=t;break;
	case half: this->neighbor2=t;break;
	case threeQuarter: this->neighbor1=t;break;
	}
}
void Tile::setRightNeighbor(Tile* t){
	switch(this->ori){
	case midday: this->neighbor2=t;break;
	case quarter: this->neighbor1=t;break;
	case half: this->neighbor4=t;break;
	case threeQuarter: this->neighbor3=t;break;
	}
}


bool Tile::canGoUp(){
	if (this->upNeighbor() == NULL) return false;
	switch(this->ori){
	case midday: return this->exit1;
	case quarter: return this->exit4;
	case half: return this->exit3;
	case threeQuarter: return this->exit2;
	}
	return false;
}
bool Tile::canGoDown(){
	switch(this->ori){
	case midday: return this->exit3;
	case quarter: return this->exit2;
	case half: return this->exit1;
	case threeQuarter: return this->exit4;
	}
	return false;
}
bool Tile::canGoLeft(){
	if (this->leftNeighbor() == NULL) return false;
	switch(this->ori){
	case midday: return this->exit4;
	case quarter: return this->exit3;
	case half: return this->exit2;
	case threeQuarter: return this->exit1;
	}
	return false;
}
bool Tile::canGoRight(){
	if(this->rightNeighbor()==NULL) return false;
	switch(this->ori){
	case midday: return this->exit2 ;
	case quarter: return this->exit1;
	case half: return this->exit4 ;
	case threeQuarter: return this->exit3;
	}
	return false;
}
Treasure* Tile::getTreasure()
{
	return this->myTreasure;
}

void Tile::setTreasure(Treasure* t)
{
	this->myTreasure=t;
}

Tile* Tile::upNeighbor(){
	switch(this->ori){
	case midday: return this->neighbor1;
	case quarter: return this->neighbor4;
	case half: return this->neighbor3;
	case threeQuarter: return this->neighbor2;
	}
	return NULL;
}
Tile* Tile::downNeighbor(){
	switch(this->ori){
	case midday: return this->neighbor3;
	case quarter: return this->neighbor2;
	case half: return this->neighbor1;
	case threeQuarter: return this->neighbor4;
	}
	return NULL;
}
Tile* Tile::leftNeighbor(){
	switch(this->ori){
	case midday: return this->neighbor4;
	case quarter: return this->neighbor3;
	case half: return this->neighbor2;
	case threeQuarter: return this->neighbor1;
	}
	return NULL;
}
Tile* Tile::rightNeighbor(){
	switch(this->ori){
	case midday: return this->neighbor2;
	case quarter: return this->neighbor1;
	case half: return this->neighbor4;
	case threeQuarter: return this->neighbor3;
	}
	return NULL;
}
Tile* Tile::clone()
{
	return new Tile(*this);
}

Tile::Tile(bool exit1,bool exit2,bool exit3,bool exit4,Orientation ori){
	this->exit1=exit1;
	this->exit2=exit2;
	this->exit3=exit3;
	this->exit4= exit4;
	this->ori=ori;
	this->myTreasure=NULL;
}
Tile::Tile(Treasure* tr,bool exit1,bool exit2,bool exit3,bool exit4,Orientation ori)
{
	this->exit1=exit1;
	this->exit2=exit2;
	this->exit3=exit3;
	this->exit4= exit4;
	this->ori=ori;
	this->myTreasure=tr;
}
Tile::Tile(Tile& t)
{
	this->exit1=t.exit1;
	this->exit2=t.exit2;
	this->exit3=t.exit3;
	this->exit4=t.exit4;
	this->ori=t.ori;
	this->myTreasure=t.myTreasure;
}

Tile::~Tile(void)
{
	delete this->myTreasure;
}
}
